//
//  chooseSexView.m
//  YiXiu
//
//  Created by ZHY on 16/7/15.
//  Copyright © 2016年 zzz. All rights reserved.
//

#import "chooseSexView.h"


@interface chooseSexView ()<UIPickerViewDelegate,UIPickerViewDataSource>

@property (nonatomic, strong) UIPickerView *sexPicker;
@property (nonatomic, strong) UIButton  *sureBtn;


@end

@implementation chooseSexView
-(instancetype)initWithFrame:(CGRect)frame{
    
    if(self = [super initWithFrame:CGRectMake(0, KScreenHeight+KScreenHeight/2, KScreenWidth, KScreenHeight/2)]){
    
        self.backgroundColor = [UIColor whiteColor];
    
        [self setUpSexPicker];
        [self setUpSureButton];
    
    }
    
    return self;
}

-(void)setUpSexPicker{
    
    
    if (!_sexPicker) {
        _sexPicker = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, KScreenWidth, KScreenHeight/2 - 40)];
        //显示选中框
        _sexPicker.showsSelectionIndicator = YES;
        _sexPicker.delegate  = self;
        _sexPicker.dataSource = self;
        [self addSubview:_sexPicker];
        
        
    }
    
    
}

-(void)setUpSureButton{
    
    if (!_sureBtn) {
        _sureBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth - 70, 10, 60, 20)];
        [_sureBtn setTitle:@"确认" forState:UIControlStateNormal];
        [_sureBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_sureBtn];
    }
    
    
    
}


//pickerView代理数据源方法
//列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    
    return 1;
}

//行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return 2;
}

//行高
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    
    return 40;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component  {
    
    if (row == 0) {
        
        NSString * man = @"男";
        
        
        [self changeUserInfo:man];
        
    }else {
        
        NSString * woman = @"女";
        
        [self changeUserInfo:woman];
        
    }
    
}


//返回当前行的每天
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    
    if (row == 0) {
        
        NSString * man = @"男";
        return man;
        
    }else {
        
        NSString * woman = @"女";
        return woman;
        
    }
    
}

//确认按钮点击事件

-(void)sureBtnAction:(UIButton *)sender{
    
    
    [UIView animateWithDuration:1 animations:^{
        self.frame = CGRectMake(0, KScreenHeight+KScreenHeight/2, KScreenWidth, KScreenHeight/2);
    }];
    
    
}

- (void)changeUserInfo:(NSString *)sex{
    /*
     u_name	String	用户昵称
     u_id	String	用户ID
     useid	String	第三方用户ID
     u_sex	String	用户性别
     u_label	String	用户标签
     u_headUrl	String	用户头像地址
     u_age	String	用户年龄
     u_marital	String	用户婚否
     u_sexual	String	用户性取向
     */
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    dic[@"u_name"] = [UserModel sharedUserModel].name;
    dic[@"u_id"] = [UserModel sharedUserModel].u_id;
    dic[@"useid"] = [UserModel sharedUserModel].userID;
    dic[@"u_sex"] = sex;
    dic[@"u_label"] = [UserModel sharedUserModel].u_label;
    dic[@"u_headUrl"] = [UserModel sharedUserModel].headImage;
    dic[@"u_age"] = [UserModel sharedUserModel].age;
    dic[@"u_marital"] = [UserModel sharedUserModel].married;
    dic[@"u_sexual"] = [UserModel sharedUserModel].sexSelect;
    
    
    [NetWorkingTool POST:@"users/usersUpdData" parameters:dic success:^(id responseObject, NSError *error) {
        
      
        
        
        
    } failure:^(id responseObject, NSError *error) {
        NSLog(@"error : %@",error);
    
        
    }];

}






@end
